package net.libra.utils
{
	/**
	 * 
	 * @author elvisjiang
	 * 
	 */	
	public class DateUtil
	{
		public static const MINUTE_IN_MILLISECONDS : Number = 60 * 1000;
		public static const HOUR_IN_MILLISECONDS : Number = 60 * 60 * 1000;
		public static const DAY_IN_MILLISECONDS : Number = 24 * 60 * 60 * 1000;
		public static const WEEK_IN_MILLISECONDS : Number = 7 * 24 * 60 * 60 * 1000;
		public static const MONTH_IN_MILLISECONDS : Number = 30 * 24 * 60 * 60 * 1000;
		public static const YEAR_IN_MILLISECONDS : Number = 12 * 30 * 24 * 60 * 60 * 1000;
		public static const CENTURY_IN_MILLISECONDS : Number = 100 * 12 * 30 * 24 * 60 * 60 * 1000;
		public static const MILLENIUM_IN_MILLISECONDS : Number = 1000 * 100 * 12 * 30 * 24 * 60 * 60 * 1000;
		
		public static function clearTime( date : Date ) : Date 
		{ 
			date.date=1;
			date.hours = 0;
			date.minutes = 0;
			date.seconds = 0;
			date.milliseconds = 0;
			
			return date;
		}
		
		public static function copyDate( date : Date ) : Date 
		{
			return new Date( date.getTime() );
		}
		
		public static function setTime( date : Date, time : Number ) : Date
		{
			date.date = Math.ceil(time / (1000 * 60 * 60 *24));
			date.hours = Math.floor(( time / (1000 * 60 * 60)) % 24);
			date.minutes = Math.floor(( time / (1000 * 60)) % 60);
			date.seconds = Math.floor(( time / 1000) % 60);
			date.milliseconds = Math.floor( time % 1000); 
			
			return date;
		}
		
		public static function addTime( date : Date, time : Number ) : Date 
		{
			date.milliseconds += time;
			
			return date;
		}
		/**
		 * format to 00:00:00
		 */
		public static function formatTimeString(hours:int,minutes:int,seconds:int):String
		{
			var h:String="";
			var m:String="";
			var s:String="";
			
			h=hours>9?hours.toString():"0"+hours.toString();
			m=minutes>9?minutes.toString():"0"+minutes.toString();
			s=seconds>9?seconds.toString():"0"+seconds.toString();
			
			return h+":"+m+":"+s;
		}
		/**
		 * format to 00:00
		 */
		public static function formatTimeToHour(hours:int,minutes:int,seconds:int):String
		{
			
			var m:String="";
			var s:String="";
			
			minutes+=hours*60;
			m=minutes>9?minutes.toString():"0"+minutes.toString();
			s=seconds>9?seconds.toString():"0"+seconds.toString();
			
			return m+":"+s;
		}
		/**
		 * @param seconds 秒
		 * format to 00:00:00
		 */
		public static function formatTimeToString2(seconds:int):String
		{
			var hour:int=seconds/3600;
			var minutes:int=seconds/60%60;
			var scecond:int=seconds-hour*3600-minutes*60;
			
			return formatTimeString(hour,minutes,scecond);
			
		}
	}
}